package com.ailanyin.admin.controller;

import com.ailanyin.model.SysErrorLog;
import com.ailanyin.admin.service.SysErrorLogService;
import com.ailanyin.common.result.AjaxResult;
import com.ailanyin.common.result.CommonPage;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author ailanyin
* @version 1.0
* @since 2022-01-04 04:41:49
*/
@RestController
@RequestMapping("/system/exception")
@Api(tags = "后台错误日志管理")
public class SysErrorLogController{

    @Autowired
    private SysErrorLogService sysErrorLogService;

    @DeleteMapping("/remove")
    @ApiOperation(value = "批量删除('system:exception:remove')")
    @PreAuthorize("hasAuthority('system:exception:remove')")
    public AjaxResult deleteByIds(@RequestBody List<String> ids) {
        sysErrorLogService.deleteByIds(ids);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取列表('system:exception:list')")
    @PreAuthorize("hasAuthority('system:exception:list')")
    public CommonPage list(SysErrorLog sysErrorLog,
                           @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                           @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysErrorLog> list = sysErrorLogService.getListByParam(sysErrorLog);
        return CommonPage.restPage(list);
    }

}
